namespace Sustainalytics.Portfolios.BL.Validators
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    using Sustainalytics.Entities;
    using Sustainalytics.Utils;
    using Sustainalytics.Utils.Validation.Interfaces;

    public class PortfolioAssociatedUniversesValidator : IValidator<SystemPortfolio, IEnumerable<Portfolio>>
    {
        public bool IsValid(SystemPortfolio entity, IEnumerable<Portfolio> entityAgainstValidate)
        {
            var sameNumber =
                entity.RelatedUniverses.Select(x => x.Id).IsEquivalentTo(entityAgainstValidate.Select(x => x.Id));
            var allAutomaticSystemPortfolios = entityAgainstValidate.All(x => x.IsAutomatic && x.IsReadonly);
            return sameNumber & allAutomaticSystemPortfolios;
        }

        public ICollection<string> BrokenRules(SystemPortfolio entity, IEnumerable<Portfolio> entityAgainstValidate)
        {
            throw new NotImplementedException();
        }
    }
}